#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int t, m, n;
	scanf("%d %d", &m, &n);
	while (m % n)
	{
		t = m % n;
		m = n;
		n = t;
	}
	printf("%d", n);
	return 0;
}
